<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Ask OpenAI</title>
    <script>
        function askOpenAI() {
            const inputElement = document.getElementById("question");
            const message = inputElement.value;
            const responseElement = document.getElementById("response");
            responseElement.textContent = ''; // Clear previous response
            var url = 'http://localhost:27779/answer/stream/analysis2?content=' + message;
            // Create an EventSource instance to listen for messages on the /ask endpoint
            const eventSource = new EventSource(url, {
                method: 'GET',
            });
            eventSource.onmessage = function (event) {
                console.log(event.data)
                // Append each message to the response element
                responseElement.textContent += "\n" + event.data;
            };

            eventSource.onerror = function (event) {
                //  responseElement.textContent = "Error: Connection was closed.";
                eventSource.close();
            };
        }
    </script>
</head>
<body>
<h1>Ask OpenAI</h1>
<textarea id="question" placeholder="Enter your question here..."></textarea><br>
<button onclick="askOpenAI()">Ask</button>
<pre id="response"></pre>
</body>
</html>
